﻿// This file is a script that can be executed with the F# Interactive.  
// It can be used to explore and test the library project.
// Note that script files will not be part of the project build.

//#r "../Debug/Cephei.Kernel.dll"
#r "../Debug/Cephei.Core.dll"
//#r "../Debug/Cephei.Data.dll"
#r "../Debug/Cephei.QL121.dll"
//#r "../Debug/Cephei.QL101.impl.dll"
#r "../Debug/Cephei.Fun121.dll"

open System
open Cephei

open System.Windows.Forms

let d = new SaveFileDialog ()
//d.Filter = @"F# files (*.fs)|*.fs|All Files (*.*)|*.*"
d.Filter = @"txt files*.txt|*.txt|All files *.txt|*.*" 
//d.FilterIndex = 1;
d.RestoreDirectory = true
d.Title = "Save model to F# source"
d.FileName = "model.fs" 
let n = d.ShowDialog ()
printf "%s\n" d.FileName 

open Cephei.Fun

let dq2 = Fun.Doubles.Create (23.1)
let d1 = 23.1
let s = Generator.ValueSource (d, true)

let sq = cell { return Fun.Quotes.SimpleQuote.Create (Some d.Value)}
let sqv = cell { yield sq.Value.Value }

let sqvd = sqv.Value 

let sq1 = Fun.Quotes.SimpleQuote.Create (Some 27.2)
let sqiv = sq1.IsValid 
let sqv1 = sq1.Value 
let f = fun () -> 23.2

let a = [1;2;3;4;5]
let av = Fun.Ints.CreateVector (a)
let t = av.[2]

//let fac = new Cephei.Cell_Factory() 
//let c1 = fac.CreateFunc (f)

//let c = new Cephei.Cell (new CalcFastFunc (f))


let dc = cell { yield 23.1}

let v = sqv.Value 

let p = ":\Development\Cephei\2.2\QuantLib-1.2.1\ql\instrument.hpp"
let pos = p.IndexOf("\\ql\\")
let incl = p.Substring (p.IndexOf ("\\ql\\"))
let s2 = @"Hello
there
!"
let sp = s2.Replace("\n", " ")



let parse (s: string)  =
    String (s.ToCharArray() |> Array.filter (fun c -> Char.IsLetterOrDigit(c)))

//let q = (new Char[]).ToString() 

let dt = DateTime.Now.AddDays (-853.0)

#r "System.Management.dll"
open System.Management
let MacAddress = 
    let mc = new ManagementClass ("Win32_NetworkAdapterConfiguration")
    let moc = mc.GetInstances()
    seq {
        let e = moc.GetEnumerator() 
        while (e.MoveNext()) do
            printf "%A" e.Current 
            yield e.Current :?> ManagementObject
        }
    |> Seq.filter (fun o -> (o.["IPEnabled"] :?> bool))
    |> Seq.map (fun o -> o.["MacAddress"] :?> string) 
    |> Seq.head 

open System.Security.Principal 
let u = WindowsIdentity.GetCurrent().Name

[|5000..9999|] |> Array.iter (fun i -> printf "f%i PROC EXPORT\n  jmp thunks + %i * 8\nf%i ENDP\n" i i i)

    
open System.Collections

let SeqEnum (e : IEnumerable) : obj seq =
    seq {
        let e = e.GetEnumerator() 
        while (e.MoveNext()) do
            yield e.Current
        }


let proc p =
    let o = p :> obj
    if o :? IEnumerable then
        let sq = Seq.fold (fun e y -> e + ";" + (y.ToString()) ) "" (SeqEnum (o :?> IEnumerable))
        printf "[%s]\n" (sq.Substring(1))
    else
        printf "%s\n" (p.ToString())

let lp (p: 'a seq) = Seq.head p
let mat (p : 'p seq seq) = Seq.head (Seq.head p)

let ds (d : DateTime) = sprintf "DateTime(%d, %d, %d)\n" d.Year d.Month d.Day 
let ss s = sprintf "\"%s\"" s
let cs s = sprintf "_%s.Value" s

open System
open System.Collections.Generic
let ls = new List<string>()
let lt = ls.GetType();

let dds = new Dictionary<string,int> ()
let ddt = dds.GetType()

let rec sourceType (t : Type) =
    if not t.IsGenericType then
        t.FullName 
    else
        let fullname = t.FullName.Substring (0, t.FullName.IndexOf ('`'))
        let pams = 
            Array.fold (fun e y -> e + "," + (sourceType y)) "" (t.GetGenericArguments())
        fullname + "<" + pams.Substring(1) + ">"
        

lt.FullName 
